﻿@using DC.Menu
@addTagHelper *, DC.Menu

<div class="top-row pl-4 navbar navbar-dark">
    <a class="navbar-brand" href="">Blazor</a>
</div>

<DCMenu>
    <DCMenuItem>
        <NavLink href="" Match="NavLinkMatch.All">Home</NavLink>
    </DCMenuItem>
    <DCMenuItem>
        <NavLink href="counter">Counter</NavLink>
    </DCMenuItem>
    <DCSubMenu Header="Sub Menu">
        <DCMenuItem>
            <NavLink href="counter">Counter</NavLink>
        </DCMenuItem>
        <DCMenuItem>
            <NavLink href="fetchdata">Fetch data</NavLink>
        </DCMenuItem>
    </DCSubMenu>
    <DCMenuItem>
        <NavLink href="fetchdata">Fetch data</NavLink>
    </DCMenuItem>
</DCMenu>

<DCMenu MenuBuilder="@MenuBuilder" />

<DCMenu ChildContent="@ChildContent" />

@functions {
        MenuBuilder MenuBuilder = new MenuBuilder();

        RenderFragment ChildContent = null;

    protected override void OnInit()
    {
        MenuBuilder.AddItem(1, "Home", "/")
                   .AddItem(2, "Counter1", "counter", IsEnabled: false)
                   .AddSubMenu(3, "Sub Menu", new MenuBuilder().AddItem(1, "Counter", "counter")
                                                               .AddItem(2, "Fetch Data", "fetchdata", IsEnabled: false)
                                                               .AddItem(3, "You Can't See Me", "invisible", IsVisible: false))
                   .AddItem(4, "FetchData", "fetchdata");

        ChildContent = new RenderFragment(b =>
        {
            b.OpenComponent<DCMenuItem>(0);
            b.AddAttribute(1, "IsEnabled", true);
            b.AddAttribute(2, "IsVisible", true);
            b.AddAttribute(3, "ChildContent", new RenderFragment(c =>
            {
                c.AddContent(4, "测试");
            }));
            b.CloseComponent();
        });
    }
}